include Makefile.config
OBJCOPY := "$(shell which arm-elf-objcopy 2>/dev/null)"
ifeq (${OBJCOPY},"")
	OBJCOPY := arm-none-eabi-objcopy
endif

all: Makefile.config update extlibs-build
	@becho "Building ndLua..."
	#nspire-gcc -static -Iextlibs/dist/include -Lextlibs/dist/lib main.c -o lua_test.elf -llua -lm
	#nspire-gcc -static -Lextlibs/dist/lib -Dluajit_c -Os -Wall -W -marm lua5.1.c -o lua5.1.elf -L$(NDLESS_PREFIX)/lib -lluajit-5.1 -lm -lndls
	nspire-gcc -Iextlibs/dist/include -Dluajit_c -Os -Wall -W -marm -c lua5.1.c
	nspire-ld lua5.1.o -o lua5.1.elf -Lextlibs/dist/lib -lluajit-5.1 -lm
	@becho "Creating ndLua TNS binary..."
	$(OBJCOPY) -O binary lua5.1.elf lua5.1.tns

extlibs-build:
	make -C extlibs

Makefile.config:
	@becho "ERROR: No Makefile configuration found. Please run ./configure first to"
	@becho "configure the build settings."
	@exit 1

clean:
	make -C extlibs clean

distclean:
	make -C extlibs distclean

update:
	@./update_check CALLED_FROM_MAKEFILE

